<?php

class Mango
{
	/**
	 * @link http://php.net/manual/en/book.mongo.php
	 * @var Mongo
	 */
	static private $mongo = null;

	/**
	 * default database name is set to null because we should use one database only.
	 */
	static private $dbname = null;

	/**
	 * get mongo object
	 * @return Mongo
	 */
	static public function getMongo()
	{
		if (null === self::$mongo)
		{
			self::$dbname = 'asap';
			self::$mongo = new Mongo("mongodb://namnv:nam123@localhost:27017/asap");
		}
		return self::$mongo;
	}

	/**
	 * @return Mongo_Collection
	 */
	static public function selectDb($name = null)
	{
		if (null == $name)
		{
			$name = self::$dbname;
		}
		return self::getMongo() -> selectDb($name);
	}

	/**
	 * @param string $collection
	 * @param string $dbname
	 * @return MongoCollection
	 */
	static public function get($collection, $db = null)
	{
		return self::getMongo() -> selectCollection(null == $db ? self::$dbname : $db, (string)$collection);
	}

	/**
	 * @var string $kind
	 * @return MongoId
	 */
	static public function idfor($kind)
	{
		return new MongoId(Nuo::idfor($kind));
	}

}
